package com.wanshi.member.controller;


import com.wanshi.member.base.Result;
import com.wanshi.member.entity.Goods;
import com.wanshi.member.entity.Member;
import com.wanshi.member.req.GoodsREQ;
import com.wanshi.member.req.MemberREQ;
import com.wanshi.member.service.IGoodsService;
import com.wanshi.member.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品信息表 前端控制器
 * </p>
 *
 *
 * @author 顽石教育-www.wanshi.com
 * @since 2021-05-08
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {


    @Autowired
    private IGoodsService goodsService;

    //    localhost:6666/member/list/search/1/20
    @PostMapping("/list/search/{page}/{size}")
    public Result search(@PathVariable("page") long page,
                         @PathVariable("size") long size,
                         @RequestBody GoodsREQ req ) {
        return goodsService.search(page, size, req);
    }


    /**
     * 新增会员
     * @param goods
     * @return
     */
    @PostMapping // post /member
    public Result add(@RequestBody Goods goods) {
        boolean b = goodsService.saveOrUpdate(goods);
        if(b) {
            return Result.ok();
        }
        return Result.error("新增会员信息失败");
    }


    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") int id) {
        boolean b = goodsService.removeById(id);
        if(b){
            return Result.ok();
        }
        return Result.error("删除会员信息失败");
    }

    @GetMapping("/{id}")
    public Result get(@PathVariable int id) {
        Goods goods = goodsService.findById(id);
        return Result.ok(goods);
    }

    /*@PutMapping("/{id}")
    public Result update(@PathVariable int id,
                         @RequestBody Goods goods) {
        return goodsService.update(id, goods);
    }*/

}
